package cn.code.mycloud.module.envir.dal.mysql.usergrid;

import cn.code.mycloud.framework.common.pojo.PageResult;
import cn.code.mycloud.framework.mybatis.core.mapper.BaseMapperX;
import cn.code.mycloud.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.code.mycloud.module.envir.controller.admin.usergrid.vo.UserGridPageReqVO;
import cn.code.mycloud.module.envir.dal.dataobject.usergrid.UserGridDO;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import org.apache.ibatis.annotations.Mapper;

import java.util.Collection;

/**
 * 用户和网格关联 Mapper
 *
 * @author 超级管理员
 */
@Mapper
public interface UserGridMapper extends BaseMapperX<UserGridDO> {

    default PageResult<UserGridDO> selectPage(UserGridPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<UserGridDO>()
                .eqIfPresent(UserGridDO::getUserId, reqVO.getUserId())
                .eqIfPresent(UserGridDO::getGridId, reqVO.getGridId())
                .betweenIfPresent(UserGridDO::getCreateTime, reqVO.getCreateTime())
                .orderByDesc(UserGridDO::getId));
    }

    default void deleteListByGridIdAndUserIds(Long gridId, Collection<Long> userIds) {
        delete(new LambdaQueryWrapper<UserGridDO>()
                .eq(UserGridDO::getGridId, gridId)
                .in(UserGridDO::getUserId, userIds));
    }
}